<?php

declare(strict_types=1);

namespace app\shop\controller\api\activity;

use think\Request;
use app\shop\controller\api\ShopBase;
use sheep\exception\SheepException;
use app\shop\service\activity\Signin as SigninLibrary;
use think\facade\Db;

class Signin extends ShopBase
{

    public function list(Request $request)
    {
        $params = $request->param();
        $month = (isset($params['month']) && $params['month']) ? date('Y-m', strtotime($params['month'])) : date('Y-m');     // 前端可能传来 2023-1,这里再统一格式化一下 month

        $signin = new SigninLibrary();
        $days = $signin->getList($month);

        $is_current = ($month == date('Y-m')) ? true : false;
        // 当前月，获取连续签到天数
        $continue_days = $signin->getContinueDays();

        $rules = $signin->getRules();

        return success('获取成功', compact('days', 'continue_days', 'rules'));
    }




    // 签到
    public function signin(Request $request)
    {
        $signin = new SigninLibrary();
        $signin = $signin->signin();

        return success('签到成功', $signin);
    }



    // 补签
    public function replenish(Request $request)
    {
        $params = $request->param();
        $this->svalidate($params, ".replenish");

        $signin = new SigninLibrary();
        $signin = $signin->replenish($params);

        return success('补签成功', $signin);
    }
}
